<!--
  -    Copyright (c) 2018-2025, gewu All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the gewucn.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: gewu
  -->

<template>
  <div class="execution">
    <el-card class="box-card btn-search">
      <div slot="header" class="clearfix">
        <div class="btn-box">
          <el-button
            type="info"
            icon="el-icon-refresh-left"
            @click="refreshChange()"
          ></el-button>
          <!-- <el-button type="info" icon="el-icon-refresh-left"></el-button> -->
          <!-- <el-button type="primary" icon="el-icon-circle-plus-outline" @click="$refs.crud.rowAdd()"
            >新增</el-button
          > -->
          <!-- <el-button type="success" icon="el-icon-edit">编辑</el-button>
          <el-button type="danger" icon="el-icon-circle-close">删除</el-button> -->
        </div>
        <div class="icon-box">
          <i class="el-icon-search"></i>
          <i class="el-icon-refresh" @click="refreshChange"></i>
          <i class="el-icon-goods"></i>
          <i
            class="el-icon-setting"
            @click="$refs.crud.$refs.dialogColumn.columnBox = !0"
          ></i>
          <i class="icon-zuixiaohua" />
        </div>
      </div>
    </el-card>
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @size-change="sizeChange"
        @current-change="currentChange"
        @refresh-change="refreshChange"
      >
        <template slot="header">
          <IconTitle class="selfTitle" title="我的任务" imgUrl="yunwei" />
          <!-- <span>所有子系统任务汇聚查看，也可以前往各子系统查看详情</span> -->
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" @click="handlePlan(scope.row)">
            <i class="el-icon-view"></i>办理</el-button
          >
          <el-button type="text"> <i class="el-icon-view"></i>委托</el-button>
          <!-- <el-dropdown-item
            v-if="permissions.act_task_manage"
            divided
            @click.native="audit(scope.row,scope.index)">审批
          </el-dropdown-item>
          <el-dropdown-item
            v-if="permissions.act_task_manage"
            divided
            @click.native="comment(scope.row,scope.index)">批注
          </el-dropdown-item>
          <el-dropdown-item
            v-if="permissions.act_task_manage"
            divided
            @click.native="viewPic(scope.row,scope.index)">流程图
          </el-dropdown-item> -->
        </template>
      </avue-crud>
    </basic-container>
    <el-dialog
      :visible.sync="dialogVisible"
      width="80%"
      append-to-body
      title="流程办理"
      fullscreen=true
    >
      <div class="iconStyle">
        <div class="con-right">
          <div class="my-steps-box">
            <template v-for="(item, index) in menulist">
              <div
                :class="['step-item', activeMenu == index ? 'step-active' : '']"
                :key="index"
                @click="chooseTag(index)"
              >
                <div class="top-title">
                  <span class="text">{{ item.label }}</span>
                </div>
              </div>
            </template>
          </div>
        </div>
        <div class="con-left" id="scrollBox">
          <el-card shadow="always" class="box-card" v-if="activeMenu == 0">
            <IconTitle class="selfTitle" title="基本信息" imgUrl="yunwei" />
            <div class="devTitle">
              <span>{{ newDetailInfo.planName }}</span>
            </div>
            <div>
              <div class="tableStyle">
                <div class="labelS">任务名称</div>
                <div class="contentS">{{ newDetailInfo.planName }}</div>
                <div class="labelS">计划编号</div>
                <div class="contentS">{{ newDetailInfo.planNum }}</div>
              </div>
              <div class="tableStyle">
                <div class="labelS">创建人</div>
                <div class="contentS">{{ newDetailInfo.createBy }}</div>
                <div class="labelS">创建时间</div>
                <div class="contentS">{{ newDetailInfo.createTime }}</div>
              </div>
              <div class="tableStyle">
                <div class="labelS">责任人</div>
                <div class="contentS">{{ newDetailInfo.liableUserName }}</div>
                <div class="labelS">计划部门</div>
                <div class="contentS">{{ newDetailInfo.deptName }}</div>
              </div>
              <!-- <div class="tableStyle">
                <div class="labelS">计划执行时间</div>
                <div class="contentS">2021-10-21 12:23:54</div>
              </div> -->
              <div class="tableStyle">
                <div class="labelS">备注</div>
                <div class="contentS">
                  {{ newDetailInfo.remark }}
                </div>
              </div>
            </div>
          </el-card>
          <el-card shadow="always" class="box-card" v-if="activeMenu == 1">
            <el-form ref="form"  label-width="80px">
              <el-form-item label="审批意见">
                <el-select v-model="yijian" placeholder="请选择审批意见">
                  <el-option :label="item" :value="item" v-for="item,index in detailInfo.optionList" :key="index"></el-option> 
                </el-select>
              </el-form-item>
              <el-form-item label="意见信息">
                <el-input
                  type="textarea"
                  :rows="5"
                  placeholder="请输入内容"
                  v-model="remark"
                >
                </el-input>
              </el-form-item>
            </el-form>
            <div class="remarkStyle"></div>

            <div class="remarkStyle" style="text-align: center">
              <el-button type="primary" @click="confirmComment"
                >确认提交</el-button
              >
            </div>
          </el-card>
          <el-card shadow="always" class="box-card" v-if="activeMenu == 2">
            <img :src="actPicUrl" width="100%" />
          </el-card>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getObj,
  fetchList,
  commetTask,
} from "@/api/gwcenter/workbench/approval";
import {
  formOption,
  tableOption,
  taskOption,
} from "@/const/crud/gwcenter/workbench/approval";
import AvueUeditor from "avue-plugin-ueditor";
import { mapGetters } from "vuex";
import IconTitle from "@/components/icon-title/index.vue";

export default {
  name: "Task",
  comments: {
    AvueUeditor,
  },
  components: {
    IconTitle,
  },
  data() {
    return {
      actPicUrl: "",
      obj: {},
      flagList: [],
      dialogVisible: false,
      tableData: [],
      taskTableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      formOption: formOption,
      taskOption: taskOption,
      activeMenu: 0,
      menulist: [
        {
          label: "附加单据",
        },
        {
          label: "任务处理",
        },
        {
          label: "流程图",
        },
      ],
      remark: "",
      id: "",
      detailInfo: {},
      newDetailInfo: {},
      yijian:'',
      businessId:''
    };
  },
  created() {},
  mounted: function () {},
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    getList(page, params) {
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize,
          },
          params
        )
      ).then((response) => {
        this.tableData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
      });
    },

    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    refreshChange() {
      this.getList(this.page);
    },
    chooseTag(index) {
      this.activeMenu = index;
    },
    achieveDetail() {
      let name = this.detailInfo.businessKey.toLowerCase() + "/";
      let id = this.detailInfo.businessId;
      getObj(id, name).then((res) => {
        this.newDetailInfo = res.data.data;
      }); 
    },
    handlePlan(row) {
      this.detailInfo = row;
      this.dialogVisible = true;
      this.id = row.taskId;
      this.businessId = row.businessId;
      this.actPicUrl = `/act/task/view/` + row.taskId;
      this.achieveDetail();
    },
    confirmComment() {
      commetTask({businessId:this.businessId, taskId: this.id, comment: this.remark,taskFlag: this.yijian}).then((res) => {
        if (res.data.code == 0) {
          this.$message.success("处理成功");
          // this.dialogVisible = false;
          this.refreshChange();
        } else {
          this.$message.error("处理失败");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/color.scss";
.devTitle {
  color: #262626;
  font-size: 20px;
  font-weight: bold;
  margin: 10px 0;
}
::v-deep.box-card {
  margin-bottom: 20px;
  .el-card__body {
    padding-top: 0;
  }
  .labelS {
    flex: 0 0 150px;
    text-align: left;
    color: #606266;
    padding: 10px;
    font-size: 12px;
    border: 1px solid rgba(236, 240, 244, 100);
    margin-bottom: -1px;
  }
  .contentS {
    border: 1px solid rgba(236, 240, 244, 100);
    color: #606266;
    font-size: 12px;
    width: 100%;
    margin-left: -1px;
    margin-bottom: -1px;
    padding: 10px;
  }
  .tableStyle {
    display: flex;
  }
}
.con-left {
  width: 70%;
}
.iconStyle {
  display: flex;
}
.con-right {
  width: 20%;
  border-right: 1px solid #ecf0f4;
  // padding-left: 23px;
  text-align: center;
  box-sizing: border-box;

  .my-steps-box {
    font-size: 12px;
    margin-top: 10px;
    .step-item {
      margin-bottom: 15px;
      padding: 6px 0;
      position: relative;
      .text {
        cursor: pointer;
      }
    }
    .step-item.step-active {
      border-right: 2px solid #26ae61;
      .text {
        color: $theme;
      }
    }
    .step-item:nth-last-child(1) .line {
      display: none;
    }
  }
}
.remarkStyle {
  margin: 10px 0;
}
</style>

